package com.yjm.test.Spring5.ch3.beanName;

import java.util.Arrays;
import java.util.Map;

import org.springframework.context.support.GenericXmlApplicationContext;

public class BeanName {

	public static void main(String[] args) {
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
		ctx.load("classpath:spring/ch3/bean-name.xml");
		ctx.refresh();
		
		String s1 = (String) ctx.getBean("jid");
		String s2 = (String) ctx.getBean("joh");
		String s3 = (String) ctx.getBean("john");
		String s4 = (String) ctx.getBean("john1");
		String s5 = (String) ctx.getBean("john2");
		String s6 = (String) ctx.getBean("jalias1");
		String s7 = (String) ctx.getBean("jalias2");
		String s8 = (String) ctx.getBean("jn");
		//String s9 = (String) ctx.getBean("ji");
		String s9 = (String) ctx.getBean("ji john000,john001;john002");
		System.out.println(System.identityHashCode(s1));
		System.out.println(System.identityHashCode(s2));
		System.out.println(System.identityHashCode(s3));
		System.out.println(System.identityHashCode(s4));
		System.out.println(System.identityHashCode(s5));
		System.out.println(System.identityHashCode(s6));
		System.out.println(System.identityHashCode(s7));
		System.out.println(System.identityHashCode(s8));
		System.out.println(System.identityHashCode(s9));
		
		Map<String, String> beans = ctx.getBeansOfType(String.class);
		if (beans.size() == 1) {
			System.out.println("There is only one String bean .");
		}
		beans.entrySet().stream().forEach(b -> {
			System.out.println("id:" + b.getKey() + "\talias:" + Arrays.toString(ctx.getAliases(b.getKey())));
		});

		ctx.close();
	}

}
